package edu.hrbu.trade01.util;

import lombok.Builder;
import lombok.Getter;

/**
 * @author 徐登宇
 */
@Getter
@Builder
public class TableR {

    // 响应码
    private Integer code;

    // 响应信息
    private String message;

    // 总数量
    private Long count;

    // 响应数据
    private Object data;

    public static final int SUCCESS_CODE = 0;
    public static final int ERROR_CODE = 201;
    public static final String SUCCESS_MESSAGE = "success";
    public static final String ERROR_MESSAGE = "error";

    public static TableR ok() {
        return TableR.builder().code(SUCCESS_CODE).message(SUCCESS_MESSAGE).build();
    }

    public static TableR ok(Long count, Object data) {
        return TableR.builder().code(SUCCESS_CODE).message(SUCCESS_MESSAGE).count(count).data(data).build();
    }

    public static TableR fail() {
        return TableR.builder().code(ERROR_CODE).message(ERROR_MESSAGE).build();
    }

    public static TableR fail(Object data) {
        return TableR.builder().code(ERROR_CODE).message(ERROR_MESSAGE).data(data).build();
    }

}
